package com.ruoyi.h5.controller;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.domain.dto.ExchangeDTO;
import com.ruoyi.system.domain.dto.RechargeDTO;
import com.ruoyi.system.service.IMiniPriceConfigService;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.system.service.h5.IRechargeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 充值相关
 * @author :liding
 * @date : 2023/11/14 11:26
 */
@RestController
@RequestMapping("/recharge")
@Slf4j
@Anonymous
public class RechargeController {

    @Autowired
    private IMiniPriceConfigService miniPriceConfigService;
    @Autowired
    private IRechargeService rechargeService;
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * vip产品列表
     * @return
     */
    @GetMapping("product")
    public AjaxResult productList(){
        return AjaxResult.success(miniPriceConfigService.selectMiniPriceConfigList(null));
    }

    /**
     * 微信充值
     * @param body
     * @return
     */
    @PostMapping("/recharge")
    public AjaxResult recharge(@RequestBody RechargeDTO body) {
        return rechargeService.recharge(body);
    }
    /**
     * 微信回调
     * @param request
     * @return
     */
    @RequestMapping(value = "/callback", method = {RequestMethod.POST, RequestMethod.GET})
    public String callback(HttpServletRequest request) {
        return rechargeService.callback(request);
    }


    /**
     * 激活码核销
     * @param body
     * @return
     */
    @PostMapping("/exchange")
    public AjaxResult exchange(@RequestBody ExchangeDTO body) {
        return rechargeService.exchange(body);
    }
    /**
     * 获取公告
     * @return
     */
    @GetMapping("/getNotice")
    public AjaxResult getNotice() {
        final List<SysNotice> sysNotices = noticeService.selectNoticeList(new SysNotice().setStatus("0"));

        return AjaxResult.success(CollUtil.isNotEmpty(sysNotices)?sysNotices.get(0):new SysNotice());
    }
}
